package com.edee.bigday.search.controller;

import com.edee.bigday.search.service.ShopSearchService;
import com.edee.bigday.search.vo.SearchParam;
import com.edee.bigday.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {
    @Autowired
    ShopSearchService shopSearchService;

    /**
     * 将页面传提交来的所有请求查询条件自动封装为指定的对象
     *
     * @param param
     * @return
     */
    //@GetMapping("/list.html")
    @GetMapping({"/list.html", "/"})
    //使http://search.bigday.com/和http://search.bigday.com/list.html均跳转到list
    public String listPage(SearchParam param, Model model, HttpServletRequest request) {
        param.set_queryString(request.getQueryString());
        //根据页面传递来的查询参数，去es中检索商品：
        SearchResult result = shopSearchService.search(param);
        model.addAttribute("result", result);
        return "list";
    }
}
